package com.huiquan.icd.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.icd.domain.IcdDiseaseHospital;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class IcdDiseaseHospitalDao extends EnhancedBaseDao<IcdDiseaseHospital> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ICD_DISEASE_HOSPITAL.";

	public IcdDiseaseHospitalDao() {
		super(space);
	}

	public int retrieveSize(Map<String, Object> param) {
		return (Integer) this.object(space + "RETRIEVE_SIZE", param, sqlMapClient);
	}

	public int retrieveSizeByStd(Map<String, Object> param) {
		return (Integer) this.object(space + "RETRIEVE_SIZE_BY_STD", param, sqlMapClient);
	}

	public int retrieveAllRightSize(Map<String, Object> param) {
		return (Integer) this.object(space + "RETRIEVE_LIST_ALL_RIGHT_SIZE", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesList(Map<String, Object> param) {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_LIST", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesListAllRight(Map<String, Object> param) {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_LIST_ALL_RIGHT", param, sqlMapClient);
	}

	public synchronized void initHospitalDiseaseStdDisable() {
		Map<String, Object> param = new HashMap<>();
		this.update(space + "INIT_HOSPITAL_DISEASE", param, sqlMapClient);
	}
	public void initHospitalDiseaseStdDisable2() {
		Map<String, Object> param = new HashMap<>();
		this.update(space + "INIT_HOSPITAL_DISEASE2", param, sqlMapClient);
	}
	public void initHospitalDisease(String std, String id) {
		Map<String, Object> param = new HashMap<>();
		param.put("std", std);
		param.put("synonymyId", id);

		this.update(space + "INIT_HOSPITAL_DISEASE_STD", param, sqlMapClient);
	}
	
	public void initCategory() {
		Map<String, Object> param = new HashMap<>();
		this.update(space + "INIT_CATEGORY", param, sqlMapClient);
	}
	public void initChapter() {
		Map<String, Object> param = new HashMap<>();
		this.update(space + "INIT_CHAPTER", param, sqlMapClient);
	}
	public void submitChecked(List<String> id, Long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("uid", uid);
		update(space + "SET_CHECK_FLAG", param, sqlMapClient);
	}

	public void changeDisable(String id, Long uid, String disable, String diseaseName) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("disable", disable);
		param.put("uid", uid);
		param.put("diseaseName", diseaseName);
		update(space + "CHANGE_DISABLE", param, sqlMapClient);
	}

	public void changeDisableSimilarCodeByStd(Long uid, String disable, String std,String similarDisease,String modifyCode) {
		Map<String, Object> param = new HashMap<>();
		param.put("disable", disable);
		param.put("uid", uid);
		param.put("std", std);
		param.put("similarDisease", similarDisease);
		param.put("modifyCode", modifyCode);
		update(space + "CHANGE_DISABLE_SIMILAR_CODE_BY_STD", param, sqlMapClient);
	}

	public void changeWrong(String id, Long uid, String disable) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("delFlag", disable);
		param.put("uid", uid);
		update(space + "CHANGE_WROING", param, sqlMapClient);
	}

	public void changeICDDisable(Long id, Long uid, String disable, String hiddenFlag) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("disable", disable);
		param.put("hiddenFlag", hiddenFlag);
		param.put("uid", uid);
		update(space + "UPDATE_ICD_DISEASE", param, sqlMapClient);
	}

	public void updateStd(String oldStd, String newStd) {
		Map<String, Object> param = new HashMap<>();
		param.put("oldStd", oldStd);
		param.put("newStd", newStd);
		update(space + "UPDATE_STD", param, sqlMapClient);
	}

	public void updateStdByDiseaseName(String diseaseName, String newStd) {
		Map<String, Object> param = new HashMap<>();
		param.put("diseaseName", diseaseName);
		param.put("newStd", newStd);
		update(space + "UPDATE_STD_BY_DISEASE_NAME", param, sqlMapClient);
	}

	public void updateCategory(String category, String std) {
		Map<String, Object> param = new HashMap<>();
		param.put("category", category);
		param.put("std", std);
		update(space + "UPDATE_CATEGORY", param, sqlMapClient);
	}
	// public void changePidGpidCategory(Long icdid, Long diseaseid) {
	// Map<String, Object> param = new HashMap<>();
	// param.put("icdid", icdid);
	// param.put("diseaseid", diseaseid);
	// update(space + "CHANGE_PID_GPID_CATEGORY", param, sqlMapClient);
	// }

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveDiSynonymyList() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_LS_DI_SYNONYMY_DATA", sqlMapClient);
	}

	public int retrieveSizeJgdmSection(Map<String, Object> param) {
		return (Integer) this.object(space + "RETRIEVE_SIZE_JGDM_SECTION", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesListJgdmSection(Map<String, Object> param) {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_LIST_JGDM_SECTION", param, sqlMapClient);
	}

	public void updateDiSynonymyStd(String id, String std) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("std", std);
		update(space + "UPDATE_LS_DI_SYNONYMY_STD", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesExportList(Map<String, Object> param) {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_EXPORT_LIST", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesCodeTypeList() {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_CODE_TYPE_LIST", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<IcdDiseaseHospital> retrievesOtherTypeList() {
		return (List<IcdDiseaseHospital>) this.list(space + "RETRIEVE_OTHER_TYPE_LIST", sqlMapClient);
	}


	@SuppressWarnings("unchecked")
	public List<Map<String, String>> checkCategoryStd() {
		return (List<Map<String, String>>) this.list(space + "CHECK_CATEGORY_STD", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> checkDisable() {
		return (List<Map<String, String>>) this.list(space + "CHECK_DISABLE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> checkCategory() {
		return (List<Map<String, String>>) this.list(space + "CHECK_CATEGORY", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrievesCategory(String category) {
		return (List<String>) this.list(space + "RETRIEVE_CATEGORY", category, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> retrieveAllDiseaseName() {
		return (List<String>) this.list(space + "RETRIEVE_ALL_DISEASE_NAME",  sqlMapClient);
	}
	public Long insertCategory(String category, long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("categoryName", category);
		param.put("uid", uid);
		return (Long) insert(space + "INSERT_CATEGORY", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getCategoryAll() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_CATEGORY_ALL", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getStdId(String std) {
		Map<String, Object> param = new HashMap<>();
		param.put("std", std);
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_STD_ID", param, sqlMapClient);
	}

	public Long insertStd(String std, long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("std", std);
		param.put("uid", uid);
		return (Long) insert(space + "INSERT_STD", param, sqlMapClient);
	}

	public void updateStdId(String diseaseName, String std, long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("diseaseName", diseaseName);
		param.put("std", std);
		param.put("uid", uid);
		update(space + "UPDATE_STD_ID", param, sqlMapClient);
	}

	public void initCategory(String id, String category) {
		Map<String, Object> param = new HashMap<>();
		param.put("synonymyId", id);
		param.put("category", category);
		update(space + "INIT_HOSPITAL_CATEGORY", param, sqlMapClient);
	}
	public void updateStdDisable(String id, String disable, long uid,String similarDisease,String modifyCode) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("uid", uid);
		param.put("disable", disable);
		param.put("similarDisease", similarDisease);
		param.put("modifyCode", modifyCode);

		update(space + "UPDATE_STD_DISABLE", param, sqlMapClient);
	}
	public void updateStdDisableCategory(String id, String disable, long uid,Long category) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("uid", uid);
		param.put("disable", disable);
		param.put("category", category);
		update(space + "UPDATE_STD_DISABLE_CATEGORY", param, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getStdAll() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_ALL_STD", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getDiseaseDisableCategory(Map<String, Object> param) {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_DISEASE_NAME_DISABLE_CATEGORY",param, sqlMapClient);
	}
}
